
public class mainS{
	static Cube Rubik = new Cube();
	static Cube Proto = new Cube();
	
	
	static public boolean flip(boolean a){ //returns the opposite of the bool it is fed, for edge orientation.
		return !a;
	}
	static public void alignProto(Cube Rubik, Cube Proto){ //Aligns the Cubes Proto and Rubik
		Proto = Rubik;
	}
	static int cOrientCycle(int orient, int typeCycle){ //Rules for the changing of corner orientation.
		/*
		    UFL : 0 -> 1; 1 -> 2; 2 -> 0; is case 0
			UFR : 0 -> 2; 1 -> 0; 2 -> 1; is case 1
			DFR : 0 -> 1; 1 -> 2; 2 -> 0; 
			DFL : 0 -> 2; 1 -> 0; 2 -> 1;
			
			NOTE: They are inverses of each other.
			
			all corner orientation transformations take place in one of these two cycles.
		 */
		if (typeCycle == 0){
			if (orient < 2) orient++;
			else orient = 0;
		}
		else if (typeCycle == 1){
			if (orient > 0) orient--;
			else orient = 2;
		}
		return orient;
	}
	
	static public void fullTurn(int typeTurn, Cube Rubik, Cube Proto){ //Full turn. Written to make writing the methods in the classes a bit easier. Most likely not used. Probably has a bug or two.
		if (typeTurn > 0){ 
			alignProto(Rubik,Proto);
			switch(typeTurn){
			case 0: // U
				Rubik.ULB.permutation = Proto.ULF.permutation;
				Rubik.ULF.permutation = Proto.URF.permutation;
				Rubik.URF.permutation = Proto.URB.permutation;
				Rubik.URB.permutation = Proto.ULB.permutation;
																				
				Rubik.UB.permutation = Proto.UL.permutation;
				Rubik.UL.permutation = Proto.UF.permutation;
				Rubik.UF.permutation = Proto.UR.permutation;
				Rubik.UR.permutation = Proto.UB.permutation;
				break;
				
			
			case 1: //D
				Rubik.DLF.permutation = Proto.DLB.permutation;
				Rubik.DLB.permutation = Proto.DRB.permutation;
				Rubik.DRB.permutation = Proto.DRF.permutation;
				Rubik.DRF.permutation = Proto.DLF.permutation;
				
				Rubik.DB.permutation = Proto.DR.permutation;
				Rubik.DR.permutation = Proto.DF.permutation;
				Rubik.DF.permutation = Proto.DL.permutation;
				Rubik.DL.permutation = Proto.DB.permutation;
				break;
				
			case 2: //F
				Rubik.ULF.permutation = Proto.DLF.permutation;
				Rubik.DLF.permutation = Proto.DRF.permutation;
				Rubik.DRF.permutation = Proto.URF.permutation;
				Rubik.URF.permutation = Proto.ULF.permutation;
				//0 is solved. 1 is twisted clockwise, CW solve. 2 is twisted counter, C to solve.
				Rubik.ULF.orientation = cOrientCycle(Proto.ULF.orientation, 0);
				Rubik.URF.orientation = cOrientCycle(Proto.URF.orientation, 1);
				Rubik.DRF.orientation = cOrientCycle(Proto.DRF.orientation, 0);
				Rubik.DLF.orientation = cOrientCycle(Proto.DLF.orientation, 1);
				
				Rubik.UF.permutation = Proto.FL.permutation;
				Rubik.FL.permutation = Proto.DF.permutation;
				Rubik.DF.permutation = Proto.FR.permutation;
				Rubik.FR.permutation = Proto.UF.permutation;
				
				Rubik.FL.orientation = flip(Proto.FL.orientation);
				Rubik.FR.orientation = flip(Proto.FR.orientation);
				Rubik.UF.orientation = flip(Proto.UF.orientation);
				Rubik.DF.orientation = flip(Proto.DF.orientation);
				break;
				
			case 3: //R
				Rubik.URF.permutation = Proto.DRF.permutation;
				Rubik.DRF.permutation = Proto.DRB.permutation;
				Rubik.DRB.permutation = Proto.URB.permutation;
				Rubik.URB.permutation = Proto.URF.permutation;
				
				Rubik.URF.orientation = cOrientCycle(Proto.URF.orientation, 0);
				Rubik.DRF.orientation = cOrientCycle(Proto.DRF.orientation, 1);
				Rubik.DRB.orientation = cOrientCycle(Proto.DRB.orientation, 0);
				Rubik.URB.orientation = cOrientCycle(Proto.URB.orientation, 1);
				
				Rubik.UR.permutation = Proto.FR.permutation;
				Rubik.FR.permutation = Proto.DR.permutation;
				Rubik.BR.permutation = Proto.BR.permutation;
				Rubik.BR.permutation = Proto.UR.permutation;
				break;
			
			case 4: //B
				Rubik.DLB.permutation = Proto.ULB.permutation;
				Rubik.ULB.permutation = Proto.URB.permutation;
				Rubik.URB.permutation = Proto.DRB.permutation;
				Rubik.DRB.permutation = Proto.DLB.permutation;
				//0 is solved. 1 is twisted clockwise, CW solve. 2 is twisted counter, C to solve.
				Rubik.ULB.orientation = cOrientCycle(Proto.ULB.orientation, 0);
				Rubik.URB.orientation = cOrientCycle(Proto.URB.orientation, 1);
				Rubik.DRB.orientation = cOrientCycle(Proto.DRB.orientation, 0);
				Rubik.DLB.orientation = cOrientCycle(Proto.DLB.orientation, 1);
				
				Rubik.BL.permutation = Proto.UB.permutation;
				Rubik.UB.permutation = Proto.BR.permutation;
				Rubik.BR.permutation = Proto.DB.permutation;
				Rubik.DB.permutation = Proto.BL.permutation;
				
				Rubik.BL.orientation = flip(Rubik.BL.orientation);
				Rubik.BR.orientation = flip(Rubik.BR.orientation);
				Rubik.UB.orientation = flip(Rubik.UB.orientation);
				Rubik.DB.orientation = flip(Rubik.DB.orientation);
				break;
			case 5: // L
				Rubik.DLF.permutation = Proto.ULF.permutation;
				Rubik.ULF.permutation = Proto.ULB.permutation;
				Rubik.ULB.permutation = Proto.DLB.permutation;
				Rubik.DLB.permutation = Proto.DLF.permutation;
				
				Rubik.ULF.orientation = cOrientCycle(Proto.ULF.orientation, 0);
				Rubik.DLF.orientation = cOrientCycle(Proto.DLF.orientation, 1);
				Rubik.DLB.orientation = cOrientCycle(Proto.DLB.orientation, 0);
				Rubik.ULB.orientation = cOrientCycle(Proto.ULB.orientation, 1);
				
				Rubik.FL.permutation = Proto.UL.permutation;
				Rubik.UL.permutation = Proto.BL.permutation;
				Rubik.BL.permutation = Proto.DL.permutation;
				Rubik.DL.permutation = Proto.FL.permutation;
				break;
			}
			alignProto(Rubik,Proto);
			fullTurn(typeTurn-6, Rubik, Proto);
		}
	}
	public static void main(String[] args) {
			System.out.println("Hello!");
			
			CornerOrientationTable COTable = new CornerOrientationTable();
			EdgeOrientationTable EOTable = new EdgeOrientationTable();
			EOTable.genEdgeOrientationTable();
			System.out.println(EOTable.eOrientTable[0][0]);
			COTable.genCornerOrientationTable();
			System.out.println(COTable.getTernary(COTable.cOrientTable[0][0]));
//			try{
//				FileOutputStream fileOut = new FileOutputStream("/EOTable.ser");
//				ObjectOutputStream out = new ObjectOutputStream(fileOut);
//				out.writeObject(EOTable);
//				out.close();
//				fileOut.close();
//				System.out.println("success?");			
//			}catch(IOException i)
//			{
//				i.printStackTrace();
//			}
			
			
	}
}
